package com.scopionstudio.djnonstop;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

/**
 * Created by hdtuan on 8/16/13.
 */
public abstract class DialogQuitApp implements View.OnClickListener {

    private final LinearLayout root;
    private final PopupWindow popupWindow;

    public DialogQuitApp(Context context) {
        LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        root = (LinearLayout) li.inflate(R.layout.dialog_quit_app, null);
        popupWindow = new PopupWindow(context);
        root.findViewById(R.id.btn_cancel).setOnClickListener(this);
        root.findViewById(R.id.btn_ok).setOnClickListener(this);
    }

    public void show(View view){
        popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setTouchable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setContentView(root);
        popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_ok:
                onClickButtonDone();
                break;
        }
        popupWindow.dismiss();
    }

    protected abstract void onClickButtonDone();
}
